package com.andbase.demo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.andbase.demo.R;
import com.andbase.demo.adapter.MenuRecyclerViewAdapter;
import com.andbase.demo.model.MenuItem;
import com.andbase.library.app.base.AbBaseActivity;
import com.andbase.library.view.recycler.AbFooterView;
import com.andbase.library.view.recycler.AbRecyclerView;
import com.andbase.library.view.recycler.AbRecyclerViewLoadMoreListener;
import com.andbase.library.view.recycler.AbSpaceItemVerticalDecoration;

import java.util.ArrayList;
import java.util.List;


public class MainActivity extends AbBaseActivity {

    private List<Object> itemList = null;
    private MenuRecyclerViewAdapter recyclerViewAdapter = null;
    private AbRecyclerView recyclerView = null;
    private AbFooterView footerView = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        initToolbar(toolbar,"AndBase Demo",false);

        itemList = new ArrayList<>();

        recyclerViewAdapter = new MenuRecyclerViewAdapter(this,itemList);

        recyclerView = (AbRecyclerView) this.findViewById(R.id.recycler_list);

        recyclerView.addItemDecoration(new AbSpaceItemVerticalDecoration(this,1));
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        //View headerView = View.inflate(this, R.layout.item_article_list_menu_header, null);
        //recyclerViewAdapter.setHeaderView(headerView);

        footerView = new AbFooterView(this);

        recyclerView.setFooterView(footerView);

        recyclerView.setRecyclerViewAdapter(recyclerViewAdapter);

        recyclerView.setRecyclerViewLoadMoreListener(new AbRecyclerViewLoadMoreListener() {
            @Override
            public void loadMore(int page) {
                loadData(page);
            }
        });

        loadData(1);
    }

    public void loadData(int page){
        footerView.setStatus(AbFooterView.STATE_LOADING);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                itemList.clear();
                MenuItem menuItem = new MenuItem(1,"日历");
                menuItem.setDescription("可高度定制的日历，容易修改");
                itemList.add(menuItem);
                footerView.setStatus(AbFooterView.STATE_FINISH);
            }
        },2000);

    }

    public void onItemClickListener(MenuItem menuItem){
        if(menuItem.getId() == 1){
            Intent intent  = new Intent(this,CalendarActivity.class);
            startActivity(intent);
        }
    }

}

